#!/bin/bash
# set -x
KAFKA_HOME=/disk2/kafka_2.10-0.8.2.2
while true; do
	# for raw-binary input
        raw_binary_processed_offset_total=0
        raw_binary_latest_offset_total=0
        time=$(date +%s)
        for i in $(cat binary_offsets)
        do
          raw_binary_processed_offset=$(echo "get /zk_test/dataplatform/storm/binary-kafka-spout/$i" | $KAFKA_HOME/bin/zookeeper-shell.sh 10.1.235.1,10.1.235.2,10.1.235.15,10.1.235.15,10.1.235.16,10.1.235.17 2>/dev/null | tail -n 1 | jq '.offset')
          raw_binary_processed_offset_total=$(expr $raw_binary_processed_offset_total + $raw_binary_processed_offset)
        done
        for h in $($KAFKA_HOME/bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 10.1.235.5:9092,10.1.235.6:9092,10.1.235.10:9092,10.1.235.11:9092 --time -1 --topic defaultUser-defaultSpace-raw-binary | awk -F [:] '{print $3}')
        do
          raw_binary_latest_offset_total=$(expr $raw_binary_latest_offset_total + $h)
        done
	echo "put goldwind.kafka.raw_binary.offset.processed.total $time $raw_binary_processed_offset_total host=$(hostname -s)"
        echo "put goldwind.kafka.raw_binary.offset.latest.total $time $raw_binary_latest_offset_total host=$(hostname -s)"
	sleep 60
done #| nc 211.154.7.134 4242
